package service

import (
	"github.com/gin-gonic/gin"
	"sensi/app/api/dto"
	"sensi/common/errcode"
	"sensi/common/frame"
	"time"
)

func (s *Service) Login(ctx *gin.Context) (interface{}, error) {
	req := &dto.LoginReq{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		return nil, err
	}

	if req.Username != "admin" || req.Password != "CmnApp!2023" {
		return nil, errcode.InvalidParam("用户名或密码错误")
	}

	ctx.SetCookie("amisToken",
		time.Now().Format(frame.TimeFormatTime), 3600, "/", "*", false, false)
	return dto.LoginResp{
		Username: req.Username,
	}, nil
}
